/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    //包含：以A为根的数是否包含B（必须从A开始）
    public boolean isSubStructure(TreeNode A, TreeNode B) {

         return (A != null && B != null) && (isSameTree(A, B) ||
          isSubStructure(A.left, B) || isSubStructure(A.right, B));

    
    }
     public boolean isSameTree(TreeNode A, TreeNode B) {
        if(null == B) {
            return true;
        }
        if(null == A && B != null) {
            return false;
        }
        if(A.val != B.val) {
            return false;
        }
        return isSameTree(A.left,B.left) && isSameTree(A.right,B.right);
        
    }
}